package models

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"strconv"
)

var (
	DB *gorm.DB
)

type DBConfig struct {
	Driver   string
	Host     string
	Username string
	Password string
	Port     int
	Database string
}

func New(config *DBConfig) error {
	var err error
	dsn := config.Username + ":" + config.Password + "@tcp(" + config.Host + ":" + strconv.Itoa(config.Port) + ")/" + config.Database + "?charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&loc=UTC"
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	return err
}
